<template>
  <svg :class="svgClass" aria-hidden="true" :style="getStyle">
    <use :xlink:href="iconName" :fill="color" />
  </svg>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'

export default defineComponent({
  inheritAttrs: false,
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    },
    size: {
      type: [Number, String],
      default: 20
    },
    color: {
      type: String,
      default: '#889aa4'
    }
  },
  setup(props) {
    return {
      iconName: computed(() => `#icon-${props.iconClass}`),
      svgClass: computed(() => {
        if (props.className) {
          return `svg-icon ${props.className}`
        }
        return `svg-icon`
      }),
      getStyle: computed(() => {
        const { size } = props
        let s = `${size}`
        s = `${s.replace('px', '')}px`
        return {
          width: s,
          height: s
        }
      })
    }
  }
})
</script>

<style scope>
.svg-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
  vertical-align: middle;
}
</style>
